<template>
  <div class="main">
    <div class="login-bar" style=" -webkit-app-region: drag;">
      <top-bar>
        <traffic-light style=" -webkit-app-region: no-drag;"></traffic-light>
        <div class="back-box">
          <img class="icon" src="@/assets/icons/left-arrowed.png" alt="right" id="back">
          <img class="icon" src="@/assets/icons/rigth-arrowed.png" alt="right">

        </div>
      </top-bar>
    </div>
    <div class="container">
      <div class="form-box" id="form-box">
        <!-- 注册 -->
        <div class="register-box hidden" id="register-box">
          <h1>register</h1>
          <input type="text" placeholder="用户名">
          <input type="email" placeholder="邮箱">
          <input type="password" placeholder="密码">
          <input type="password" placeholder="确认密码">
          <button>注册</button>
        </div>
        <!-- 登录 -->
        <div class="login-box" id="login-box">
          <h1>login</h1>
          <input type="text" placeholder="用户名">
          <input type="password" placeholder="密码">
          <button>登录</button>
        </div>
      </div>
      <div class="con-box left">
        <h2>欢迎来到<span>World Box</span></h2>
        <img src="../../assets/icons/logo.png" alt="">
        <p>已有账号</p>
        <button id="login">去登录</button>
      </div>
      <div class="con-box right">
        <h2>欢迎来到<span>World Box</span></h2>
        <img src="../../assets/icons/logo.png" alt="">
        <p>没有账号？</p>
        <button id="register">去注册</button>
      </div>
    </div>
  </div>

</template>

<script lang="ts" setup>
import {onMounted} from "vue";
import TrafficLight from "@/components/traffic-light.vue";
import TopBar from "@/components/top-bar.vue"
import router from "@/router";
import {useThemeStore} from "@/stores/themes";

onMounted(() => {
  const useStore = useThemeStore()
  let back = document.querySelector("#back") as HTMLImageElement
  let form_box = document.querySelector("#form-box") as HTMLDivElement
  let login_box = document.querySelector('#login-box') as HTMLDivElement
  let register_box = document.querySelector('#register-box') as HTMLDivElement
  let login = document.querySelector('#login') as HTMLButtonElement
  let register = document.querySelector('#register') as HTMLButtonElement
  form_box.style.background = useStore.getColor()
  login.addEventListener('click', () => {
        form_box.classList.add("login-transform")

        form_box.classList.remove("register-transform")
        login_box.classList.remove('hidden');
        register_box.classList.add('hidden');
      }
  )
  back.addEventListener("click", () => {
    router.back()
  })


  register.addEventListener("click", () => {
    form_box.classList.add("register-transform")
    form_box.classList.remove("login-transform")
    register_box.classList.remove('hidden');
    login_box.classList.add('hidden');
  })

})

</script>

<style lang="less" scoped>
.main {
  width: 100vw;
  height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;

  .back-box {
    width: 100px;
    display: flex;
    height: 100%;
    position: absolute;
    -webkit-app-region: no-drag;
    left: 150px;
    align-items: center;
    top: 5px;
    justify-content: space-between;

    .icon {
      width: 18px;
      height: 24px;
      cursor: pointer;
      padding: 5px;
      border-radius: 50%;
    }

    .icon:hover {
      background-color: #d9d9d9;
    }
  }

  .login-bar {
    width: 100%;
    height: 45px;
    display: flex;

    align-items: center;
    position: absolute;
    top: 0;
  }
}

.login-transform {
  transform: translateX(-10%);
}

.register-transform {
  transform: translateX(90%);
}

.container {
  background: url("@/assets/icons/transparent-big.png");

  width: 650px;
  height: 415px;
  border-radius: 5px;
  /* 阴影 */
  box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
  /* 相对定位 */
  position: relative;
}

.form-box {
  /* 绝对定位 */
  position: absolute;
  top: -10%;
  left: 5%;
  background-image: linear-gradient(to top, #df89b5 0%, #bfd9fe 100%);
  width: 320px;
  height: 500px;
  border-radius: 5px;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2;
  /* 动画过渡 加速后减速 */
  transition: 0.5s ease-in-out;
}

.register-box, .login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.hidden {
  display: none;
  transition: 0.5s;
}

h1 {
  text-align: center;
  margin-bottom: 25px;
  /* 大写 */
  text-transform: uppercase;
  color: #fff;
  /* 字间距 */
  letter-spacing: 5px;
}

input {
  background-color: transparent;
  width: 70%;
  color: #fff;
  border: none;
  /* 下边框样式 */
  border-bottom: 1px solid rgba(255, 255, 255, 0.4);
  padding: 10px 0;
  text-indent: 10px;
  margin: 8px 0;
  font-size: 14px;
  letter-spacing: 2px;
}

input::placeholder {
  color: #fff;
}

input:focus {
  color: #a262ad;
  outline: none;
  border-bottom: 1px solid #a262ad80;
  transition: 0.5s;
}

input:focus::placeholder {
  opacity: 0;
}

.form-box button {
  width: 70%;
  margin-top: 35px;
  background-color: #f6f6f6;
  outline: none;
  border-radius: 8px;
  padding: 13px;
  color: #a262ad;
  letter-spacing: 2px;
  border: none;
  cursor: pointer;
}

.form-box button:hover {
  background-color: #a262ad;
  color: #f6f6f6;
  transition: background-color 0.5s ease;
}

.con-box {
  width: 50%;
  /* 弹性布局 垂直排列 居中 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* 绝对定位 居中 */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.con-box.left {
  left: -2%;
}

.con-box.right {
  right: -2%;
}

.con-box h2 {
  color: #8e9aaf;
  font-size: 25px;
  font-weight: bold;
  letter-spacing: 3px;
  text-align: center;
  margin-bottom: 4px;
}

.con-box p {
  font-size: 12px;
  letter-spacing: 2px;
  color: #8e9aaf;
  text-align: center;
}

.con-box span {
  color: #d3b7d8;
}

.con-box img {
  width: 130px;
  height: 150px;
  opacity: 0.9;
  margin: 40px 0;
}

.con-box button {
  margin-top: 3%;
  background-color: #fff;
  color: #a262ad;
  border: 1px solid #d3b7d8;
  padding: 6px 10px;
  border-radius: 5px;
  letter-spacing: 1px;
  outline: none;
  cursor: pointer;
}

.con-box button:hover {
  background-image: linear-gradient(to right, #243949 0%, #517fa4 100%);
  background-blend-mode: normal, color-burn;
  color: #fff;
}
</style>